/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PFaceDetection.java
 *
 * Created on Mar 22, 2012, 4:09:11 PM
 */
package com.bc5Neptune.cis.gui;

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import com.bc5Neptune.cis.bll.FaceDetection;
import static com.bc5Neptune.cis.bll.GlobalObject.*;
import com.bc5Neptune.cis.bll.IconList;
import com.bc5Neptune.cis.bll.ProcessFile;
import com.bc5Neptune.cis.bll.ProcessImage;
import com.bc5Neptune.cis.bll.ReadFolder;
import com.bc5Neptune.cis.bll.VerticalIconRender;
import com.bc5Neptune.cis.dal.PersonDAL;
import com.bc5Neptune.cis.entity.*;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author phu.huynh
 */
public class PFaceDetection extends JPanel {
    /*
     * control disable or enable region
     */

    final int SORT_INCREASE = 1;
    boolean toggleRegion = false;
    String tempPath;
    String groupRes;
    String groupHTown;
    /*
     * save icon for list render
     */
    public ArrayList<IconList> iconTrainArr = new ArrayList<IconList>();
    /*
     * save 10 faces to insert to database
     */
    public ArrayList<IconList> iconTempArr = new ArrayList<IconList>();
    public ArrayList<Integer> indexArr = new ArrayList<Integer>();

    public PFaceDetection() {
        initComponents();
        //show a person who access
        initialInformationForm();
        
        //set visible
        //pnlShowAdd.setVisible(false);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fileChooseFolder = new javax.swing.JFileChooser();
        jFileChooser1 = new javax.swing.JFileChooser();
        jSplitPane3 = new javax.swing.JSplitPane();
        jPanel10 = new javax.swing.JPanel();
        btnOpenFolder = new javax.swing.JButton();
        jPanel20 = new javax.swing.JPanel();
        jTabbedPane3 = new javax.swing.JTabbedPane();
        jPanel21 = new javax.swing.JPanel();
        jSplitPane4 = new javax.swing.JSplitPane();
        jPanel22 = new javax.swing.JPanel();
        jPanel23 = new javax.swing.JPanel();
        scrollPanelThumb = new javax.swing.JScrollPane();
        lstThumbnails = new javax.swing.JList();
        jPanel25 = new javax.swing.JPanel();
        splMain1 = new javax.swing.JSplitPane();
        jPanel26 = new javax.swing.JPanel();
        pnlShowImage = new javax.swing.JPanel();
        pnlFaceAnotations1 = new javax.swing.JPanel();
        scrollFaceImages = new javax.swing.JScrollPane();
        lstFaceImages = new javax.swing.JList();
        jPanel30 = new javax.swing.JPanel();
        jSplitPane5 = new javax.swing.JSplitPane();
        pnlShowAdd = new javax.swing.JPanel();
        jPanel46 = new javax.swing.JPanel();
        lblClickToLoad = new javax.swing.JLabel();
        lblLoadImg = new javax.swing.JLabel();
        jPanel47 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        txfRel = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        txfEthnic = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        txfIdNumber = new javax.swing.JTextField();
        jLabel29 = new javax.swing.JLabel();
        txfDOB = new javax.swing.JTextField();
        txfFname = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txaChar = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        cbbHTownPrv = new javax.swing.JComboBox();
        cbbHTownDis = new javax.swing.JComboBox();
        cbbHTownWrd = new javax.swing.JComboBox();
        cbbHTownGrp = new javax.swing.JComboBox();
        cbbResidencePrv = new javax.swing.JComboBox();
        cbbResidenceDis = new javax.swing.JComboBox();
        cbbResidenceWrd = new javax.swing.JComboBox();
        cbbResidenceGrp = new javax.swing.JComboBox();
        btnSave = new javax.swing.JButton();
        btnReset = new javax.swing.JButton();
        lblNote = new javax.swing.JLabel();
        jPanel48 = new javax.swing.JPanel();
        jPanel49 = new javax.swing.JPanel();
        scrollTrainFace = new javax.swing.JScrollPane();
        lstTrainFace = new javax.swing.JList();
        jPanel50 = new javax.swing.JPanel();
        cmbTrainFace = new javax.swing.JComboBox();

        setName("Face Detection"); // NOI18N

        jSplitPane3.setDividerLocation(50);
        jSplitPane3.setDividerSize(1);
        jSplitPane3.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jPanel10.setBackground(java.awt.Color.gray);

        btnOpenFolder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/must_have_icon_set/Open/Open_32x32.png"))); // NOI18N
        btnOpenFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOpenFolderActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnOpenFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(786, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnOpenFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jSplitPane3.setTopComponent(jPanel10);

        jTabbedPane3.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);
        jTabbedPane3.setFocusable(false);
        jTabbedPane3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPane3MouseClicked(evt);
            }
        });

        jSplitPane4.setDividerLocation(150);
        jSplitPane4.setDividerSize(1);

        jPanel23.setBorder(javax.swing.BorderFactory.createTitledBorder("Thumbnails"));

        lstThumbnails.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        lstThumbnails.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstThumbnailsMouseClicked(evt);
            }
        });
        lstThumbnails.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstThumbnailsValueChanged(evt);
            }
        });
        scrollPanelThumb.setViewportView(lstThumbnails);

        javax.swing.GroupLayout jPanel23Layout = new javax.swing.GroupLayout(jPanel23);
        jPanel23.setLayout(jPanel23Layout);
        jPanel23Layout.setHorizontalGroup(
            jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollPanelThumb, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
        );
        jPanel23Layout.setVerticalGroup(
            jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollPanelThumb, javax.swing.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel22Layout = new javax.swing.GroupLayout(jPanel22);
        jPanel22.setLayout(jPanel22Layout);
        jPanel22Layout.setHorizontalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel23, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel22Layout.setVerticalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel23, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jSplitPane4.setLeftComponent(jPanel22);

        splMain1.setDividerLocation(500);
        splMain1.setDividerSize(1);
        splMain1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        pnlShowImage.setBackground(new java.awt.Color(102, 102, 102));
        pnlShowImage.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlShowImage.setAlignmentX(0.0F);
        pnlShowImage.setAlignmentY(0.0F);
        pnlShowImage.setAutoscrolls(true);

        javax.swing.GroupLayout pnlShowImageLayout = new javax.swing.GroupLayout(pnlShowImage);
        pnlShowImage.setLayout(pnlShowImageLayout);
        pnlShowImageLayout.setHorizontalGroup(
            pnlShowImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 661, Short.MAX_VALUE)
        );
        pnlShowImageLayout.setVerticalGroup(
            pnlShowImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 496, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel26Layout = new javax.swing.GroupLayout(jPanel26);
        jPanel26.setLayout(jPanel26Layout);
        jPanel26Layout.setHorizontalGroup(
            jPanel26Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlShowImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel26Layout.setVerticalGroup(
            jPanel26Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlShowImage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        splMain1.setTopComponent(jPanel26);

        pnlFaceAnotations1.setBorder(javax.swing.BorderFactory.createTitledBorder("Face Anotations"));
        pnlFaceAnotations1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        pnlFaceAnotations1.setMaximumSize(new java.awt.Dimension(594, 126));

        scrollFaceImages.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        lstFaceImages.setLayoutOrientation(javax.swing.JList.HORIZONTAL_WRAP);
        lstFaceImages.setName("listFace"); // NOI18N
        lstFaceImages.setVisibleRowCount(1);
        scrollFaceImages.setViewportView(lstFaceImages);

        javax.swing.GroupLayout pnlFaceAnotations1Layout = new javax.swing.GroupLayout(pnlFaceAnotations1);
        pnlFaceAnotations1.setLayout(pnlFaceAnotations1Layout);
        pnlFaceAnotations1Layout.setHorizontalGroup(
            pnlFaceAnotations1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollFaceImages, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 653, Short.MAX_VALUE)
        );
        pnlFaceAnotations1Layout.setVerticalGroup(
            pnlFaceAnotations1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollFaceImages, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
        );

        splMain1.setBottomComponent(pnlFaceAnotations1);

        javax.swing.GroupLayout jPanel25Layout = new javax.swing.GroupLayout(jPanel25);
        jPanel25.setLayout(jPanel25Layout);
        jPanel25Layout.setHorizontalGroup(
            jPanel25Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(splMain1, javax.swing.GroupLayout.DEFAULT_SIZE, 665, Short.MAX_VALUE)
        );
        jPanel25Layout.setVerticalGroup(
            jPanel25Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(splMain1, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
        );

        jSplitPane4.setRightComponent(jPanel25);

        javax.swing.GroupLayout jPanel21Layout = new javax.swing.GroupLayout(jPanel21);
        jPanel21.setLayout(jPanel21Layout);
        jPanel21Layout.setHorizontalGroup(
            jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 816, Short.MAX_VALUE)
        );
        jPanel21Layout.setVerticalGroup(
            jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
        );

        jTabbedPane3.addTab("Image Brower", jPanel21);

        jSplitPane5.setDividerLocation(150);
        jSplitPane5.setDividerSize(1);

        pnlShowAdd.setBackground(java.awt.Color.gray);

        jPanel46.setBackground(java.awt.Color.gray);
        jPanel46.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Original Image", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.white));

        lblClickToLoad.setForeground(java.awt.Color.white);
        lblClickToLoad.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblClickToLoad.setText("Click me to import a image");
        lblClickToLoad.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblClickToLoadMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel46Layout = new javax.swing.GroupLayout(jPanel46);
        jPanel46.setLayout(jPanel46Layout);
        jPanel46Layout.setHorizontalGroup(
            jPanel46Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblLoadImg, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
            .addGroup(jPanel46Layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addComponent(lblClickToLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(45, Short.MAX_VALUE))
        );
        jPanel46Layout.setVerticalGroup(
            jPanel46Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel46Layout.createSequentialGroup()
                .addComponent(lblLoadImg, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblClickToLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel47.setBackground(java.awt.Color.gray);

        jLabel22.setForeground(java.awt.Color.white);
        jLabel22.setText("Full name:");

        jLabel25.setForeground(java.awt.Color.white);
        jLabel25.setText("Identity Number:");

        jLabel27.setForeground(java.awt.Color.white);
        jLabel27.setText("Birthday:");

        txfEthnic.setBackground(java.awt.Color.lightGray);

        jLabel28.setForeground(java.awt.Color.white);
        jLabel28.setText("People:");

        jLabel29.setForeground(java.awt.Color.white);
        jLabel29.setText("Religious:");

        txfFname.setBackground(java.awt.Color.lightGray);

        jLabel5.setForeground(java.awt.Color.white);
        jLabel5.setText("Characteristic:");

        txaChar.setBackground(java.awt.Color.lightGray);
        txaChar.setColumns(20);
        txaChar.setRows(5);
        jScrollPane2.setViewportView(txaChar);

        javax.swing.GroupLayout jPanel47Layout = new javax.swing.GroupLayout(jPanel47);
        jPanel47.setLayout(jPanel47Layout);
        jPanel47Layout.setHorizontalGroup(
            jPanel47Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel47Layout.createSequentialGroup()
                .addGroup(jPanel47Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
                    .addComponent(jLabel25, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel22, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txfIdNumber, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
                    .addComponent(jLabel28, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel29, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txfFname, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
                    .addComponent(jLabel27, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txfDOB, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel47Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txfEthnic, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txfRel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel47Layout.setVerticalGroup(
            jPanel47Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel47Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel25)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txfIdNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txfFname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel27)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(txfDOB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel28)
                .addGap(4, 4, 4)
                .addComponent(txfEthnic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel29)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txfRel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel4.setBackground(java.awt.Color.gray);

        jLabel6.setForeground(java.awt.Color.white);
        jLabel6.setText("Hometown:");

        jLabel7.setForeground(java.awt.Color.white);
        jLabel7.setText("Residence:");

        cbbHTownPrv.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select Province--" }));

        cbbHTownDis.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select District--" }));

        cbbHTownWrd.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select Ward--" }));

        cbbHTownGrp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select Group--" }));

        cbbResidencePrv.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select Province--" }));

        cbbResidenceDis.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select District--" }));
        cbbResidenceDis.setName(""); // NOI18N

        cbbResidenceWrd.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select Ward--" }));

        cbbResidenceGrp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select Group--" }));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbbHTownPrv, 0, 168, Short.MAX_VALUE)
                            .addComponent(cbbResidencePrv, 0, 168, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(cbbResidenceDis, 0, 149, Short.MAX_VALUE)
                            .addComponent(cbbHTownDis, 0, 149, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbbResidenceWrd, 0, 135, Short.MAX_VALUE)
                            .addComponent(cbbHTownWrd, 0, 135, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbbResidenceGrp, 0, 142, Short.MAX_VALUE)
                            .addComponent(cbbHTownGrp, 0, 142, Short.MAX_VALUE))
                        .addGap(48, 48, 48))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addContainerGap(581, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addContainerGap(589, Short.MAX_VALUE))))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jLabel6)
                .addGap(14, 14, 14)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbbHTownGrp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbHTownDis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbHTownWrd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbHTownPrv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbbResidenceDis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbResidenceWrd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbResidenceGrp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbResidencePrv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49))
        );

        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/must_have_icon_set/Save/Save_24x24.png"))); // NOI18N
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnReset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/must_have_icon_set/Redo/Redo_24x24.png"))); // NOI18N
        btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetActionPerformed(evt);
            }
        });

        lblNote.setFont(new java.awt.Font("Cantarell", 0, 18)); // NOI18N
        lblNote.setForeground(java.awt.Color.red);
        lblNote.setText("   ");

        javax.swing.GroupLayout pnlShowAddLayout = new javax.swing.GroupLayout(pnlShowAdd);
        pnlShowAdd.setLayout(pnlShowAddLayout);
        pnlShowAddLayout.setHorizontalGroup(
            pnlShowAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlShowAddLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlShowAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlShowAddLayout.createSequentialGroup()
                        .addGroup(pnlShowAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblNote, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
                            .addComponent(jPanel46, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(30, 30, 30))
                    .addGroup(pnlShowAddLayout.createSequentialGroup()
                        .addComponent(btnReset)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jPanel47, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(51, 51, 51))
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pnlShowAddLayout.setVerticalGroup(
            pnlShowAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlShowAddLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlShowAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlShowAddLayout.createSequentialGroup()
                        .addComponent(jPanel46, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblNote, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(pnlShowAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btnSave, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                            .addComponent(btnReset, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(pnlShowAddLayout.createSequentialGroup()
                        .addComponent(jPanel47, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64))
        );

        jSplitPane5.setRightComponent(pnlShowAdd);

        jPanel49.setBorder(javax.swing.BorderFactory.createTitledBorder("Know Faces"));

        lstTrainFace.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        scrollTrainFace.setViewportView(lstTrainFace);

        javax.swing.GroupLayout jPanel49Layout = new javax.swing.GroupLayout(jPanel49);
        jPanel49.setLayout(jPanel49Layout);
        jPanel49Layout.setHorizontalGroup(
            jPanel49Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollTrainFace, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
        );
        jPanel49Layout.setVerticalGroup(
            jPanel49Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollTrainFace, javax.swing.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE)
        );

        jPanel50.setBorder(javax.swing.BorderFactory.createTitledBorder("Choose name"));

        cmbTrainFace.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All image" }));
        cmbTrainFace.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTrainFaceActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel50Layout = new javax.swing.GroupLayout(jPanel50);
        jPanel50.setLayout(jPanel50Layout);
        jPanel50Layout.setHorizontalGroup(
            jPanel50Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(cmbTrainFace, 0, 0, Short.MAX_VALUE)
        );
        jPanel50Layout.setVerticalGroup(
            jPanel50Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel50Layout.createSequentialGroup()
                .addComponent(cmbTrainFace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel48Layout = new javax.swing.GroupLayout(jPanel48);
        jPanel48.setLayout(jPanel48Layout);
        jPanel48Layout.setHorizontalGroup(
            jPanel48Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel50, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel49, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel48Layout.setVerticalGroup(
            jPanel48Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel48Layout.createSequentialGroup()
                .addComponent(jPanel50, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel49, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jSplitPane5.setLeftComponent(jPanel48);

        javax.swing.GroupLayout jPanel30Layout = new javax.swing.GroupLayout(jPanel30);
        jPanel30.setLayout(jPanel30Layout);
        jPanel30Layout.setHorizontalGroup(
            jPanel30Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 816, Short.MAX_VALUE)
        );
        jPanel30Layout.setVerticalGroup(
            jPanel30Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
        );

        jTabbedPane3.addTab("Face Database", jPanel30);

        javax.swing.GroupLayout jPanel20Layout = new javax.swing.GroupLayout(jPanel20);
        jPanel20.setLayout(jPanel20Layout);
        jPanel20Layout.setHorizontalGroup(
            jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 828, Short.MAX_VALUE)
        );
        jPanel20Layout.setVerticalGroup(
            jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 663, Short.MAX_VALUE)
        );

        jSplitPane3.setRightComponent(jPanel20);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 828, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane3)
        );
    }// </editor-fold>//GEN-END:initComponents

    public void loadImageToLabelEvent() {

        /*
         * empty icon lable
         */
        lblLoadImg.setIcon(null);
        jFileChooser1.setDialogTitle("Choose a file");
        //this.getContentPane().add(jFileChooser1);
        jFileChooser1.setVisible(true);
        int returnVal = jFileChooser1.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File selectedFile = jFileChooser1.getSelectedFile();
            tempPath = selectedFile.getAbsolutePath();
            int ind = tempPath.lastIndexOf(".");
            if (ind == -1) { // no file type
                JOptionPane.showConfirmDialog(this,
                        "Please choose .jpg or .jpeg type!", "Warning",
                        JOptionPane.CLOSED_OPTION,
                        JOptionPane.WARNING_MESSAGE);
                return;
            }
            String tmp = tempPath.substring(ind);
            if (tmp.equalsIgnoreCase(".jpg") == false // .jpg or jpeg
                    || tmp.equalsIgnoreCase(".jpeg")) {
                JOptionPane.showConfirmDialog(this,
                        "Please choose .jpg or .jpeg type!", "Warning",
                        JOptionPane.CLOSED_OPTION,
                        JOptionPane.WARNING_MESSAGE);
                return;
            }
            //App.objImage.setPath(tempPath);
            BufferedImage image = null;
            File file = new File(tempPath);
            System.out.println(file.getAbsolutePath());
            try {
                image = javax.imageio.ImageIO.read(file);
            } catch (IOException ex) {
                System.out.println("Can't load image " + tempPath);
                JOptionPane.showConfirmDialog(this, "Please reload image!",
                        "Warning", JOptionPane.CLOSED_OPTION,
                        JOptionPane.WARNING_MESSAGE);
            }
            BufferedImage resizeImage = null;
            ProcessImage objImage = new ProcessImage();
            resizeImage = objImage.resize(image, 300, 200);
            lblLoadImg.setIcon(new ImageIcon(resizeImage));
            /*
             * resize image
             */
            //objImage.resizeImage(tempPath, 500, 500, Config.PATH_TMP_DETECT);
        }
    }

    public void choseFolder() {
        fileChooseFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        int returnVal = fileChooseFolder.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {

            File folderSelected = fileChooseFolder.getSelectedFile();
            final String folder = folderSelected.getAbsolutePath() + "/";
            System.out.println(folder);

            lstThumbnails.setCellRenderer(null); //clear cell render

            final ReadFolder readFolder = new ReadFolder(folder, "image");
            String[] files = readFolder.read(SORT_INCREASE);
            // init value for ImageList 
            GLImageList.setFileImages(files);
            GLImageList.setPathFolder(folder);
            /*
             * thread to read the images
             */
            new Thread() {

                public void run() {
                    //GLImageList.cvload();
                    //resize image 90 X 120
                    int length = GLImageList.getLength(); //length of name of files
                    if (length > 0) {
                        IconList[] iconList = new IconList[length];
                        /*
                         * inilization a object of icon class show it in a
                         * listbox
                         */
                        for (int i = 0; i < length; i++) {
                            GLImageList.load(i);
                            iconList[i] = new IconList();
                            //resize befor add to list
                            ProcessImage proImg = new ProcessImage();
                            BufferedImage tmpImg = proImg.resize(GLImageList.getImage(), 92, 112);
                            iconList[i].setImage(tmpImg);
                        }

                        /*
                         * set value of render
                         */
                        lstThumbnails = new JList(iconList);
                        VerticalIconRender renderer = new VerticalIconRender();
                        lstThumbnails.setCellRenderer(renderer);
                    }
                    /*
                     * clear pnlShowImage and list face
                     */
                    pnlShowImage.revalidate();
                    pnlShowImage.repaint();

                    /*
                     * set event click
                     */
                    lstThumbnails.addMouseListener(new ListImageListener());
                    /*
                     * add jlist on scrollPanel
                     */
                    scrollPanelThumb.setViewportView(lstThumbnails);

                    /*
                     * init face region
                     */
                    GLPCustom.positionArr = new FaceRegion[GLImageList.getLength()];
                    GLPCustom.index = 0;
                    interrupt();
                }
                /*
                 * show the images in list
                 */
            }.start();
        }
    }
    private void btnOpenFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenFolderActionPerformed

        choseFolder();
    }//GEN-LAST:event_btnOpenFolderActionPerformed

    private void lstThumbnailsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstThumbnailsMouseClicked
        // TODO add your handling code here:
        System.out.println(lstThumbnails.getSelectedIndex());
        //set cellrender again

    }//GEN-LAST:event_lstThumbnailsMouseClicked

    private void lstThumbnailsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstThumbnailsValueChanged
        // TODO add your handling code here:
        System.out.println("Hele");
    }//GEN-LAST:event_lstThumbnailsValueChanged
    E2 ee2 = new E2();
    E3 ee3 = new E3();
    E4 ee4 = new E4();
    //------------------------
    E6 ee6 = new E6();
    E7 ee7 = new E7();
    E8 ee8 = new E8();

    private void initialInformationForm() {
        // initialize list entity of CountryEntity
        PersonDAL prsDal = new PersonDAL();
        List<ProvinceEntity> listEntity = prsDal.getListProvince();
        for (ProvinceEntity Province : listEntity) {
            cbbHTownPrv.addItem(Province);
            cbbResidencePrv.addItem(Province);
        }
        FilterProvinceHTown ee1 = new FilterProvinceHTown();
        cbbHTownPrv.addActionListener(ee1);

        cbbHTownDis.addActionListener(ee2);

        cbbHTownWrd.addActionListener(ee3);

        cbbHTownGrp.addActionListener(ee4);

        FilterProvinceRes ee5 = new FilterProvinceRes();
        cbbResidencePrv.addActionListener(ee5);
        cbbResidenceDis.addActionListener(ee6);
        cbbResidenceWrd.addActionListener(ee7);
        cbbResidenceGrp.addActionListener(ee8);

    }

    public int removeE2() {
        int i = 0;
        if (cbbHTownPrv.getSelectedIndex() == 0) {
            cbbHTownDis.removeActionListener(ee2);
            cbbHTownDis.removeAllItems();
            cbbHTownDis.addItem("--Select District--");
            cbbHTownDis.addActionListener(ee2);
        } else {
            if (cbbHTownDis.getItemAt(1) != null) {
                cbbHTownDis.removeActionListener(ee2);
                cbbHTownDis.removeAllItems();
                cbbHTownDis.addItem("--Select District--");
                cbbHTownDis.addActionListener(ee2);
                //i =1;
            }
            i = 1;
        }

        return i;
    }

    public void removeE3() {
        if (cbbHTownWrd.getItemAt(1) != null) {
            cbbHTownWrd.removeActionListener(ee3);
            cbbHTownWrd.removeAllItems();
            cbbHTownWrd.addItem("--Select Ward--");
            cbbHTownWrd.addActionListener(ee3);
        }
    }

    public void removeE4() {
        if (cbbHTownGrp.getItemAt(1) != null) {
            cbbHTownGrp.removeActionListener(ee4);
            cbbHTownGrp.removeAllItems();
            cbbHTownGrp.addItem("--Select group--");
            cbbHTownGrp.addActionListener(ee4);
        }
    }

    public int removeE6() {
        int i = 0;
        if (cbbResidencePrv.getSelectedIndex() == 0) {
            cbbResidenceDis.removeActionListener(ee6);
            cbbResidenceDis.removeAllItems();
            cbbResidenceDis.addItem("--Select District--");
            cbbResidenceDis.addActionListener(ee6);
        } else {
            if (cbbResidenceDis.getItemAt(1) != null) {
                cbbResidenceDis.removeActionListener(ee6);
                cbbResidenceDis.removeAllItems();
                cbbResidenceDis.addItem("--Select District--");
                cbbResidenceDis.addActionListener(ee6);
                //i =1;
            }
            i = 1;
        }

        return i;
    }

    public void removeE7() {
        if (cbbResidenceWrd.getItemAt(1) != null) {
            cbbResidenceWrd.removeActionListener(ee7);
            cbbResidenceWrd.removeAllItems();
            cbbResidenceWrd.addItem("--Select Ward--");
            cbbResidenceWrd.addActionListener(ee7);
        }
    }

    public void removeE8() {
        if (cbbResidenceGrp.getItemAt(1) != null) {
            cbbResidenceGrp.removeActionListener(ee8);
            cbbResidenceGrp.removeAllItems();
            cbbResidenceGrp.addItem("--Select group--");
            cbbResidenceGrp.addActionListener(ee8);
        }
    }

    public class FilterProvinceHTown implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e1) {
            System.out.println("Clicking Province Home Town");
            PersonDAL prsDal = new PersonDAL();
//                if (cbbHTownDis.getSelectedIndex() == 0) {
//                    cbbHTownDis.removeAllItems();
//                    cbbHTownDis.addItem("--Select District--");
            ProvinceEntity Province = (ProvinceEntity) cbbHTownPrv.getSelectedItem();
            System.out.println("ID of province: " + Province.getProvinceID().toString());
            HashSet<DistrictEntity> listDistrict = prsDal.getListDistrict(Province.getProvinceID());
            int i = removeE2();
            if (i == 1) {
                for (DistrictEntity district : listDistrict) {
                    cbbHTownDis.addItem(district);
                }
            }

        }
    }

    public class E2 implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e2) {
            System.out.println("Clicking District");
            //cbbHTownWrd.removeAllItems();
            // cbbHTownWrd.addItem("--Choose Ward--");
            PersonDAL prsDal = new PersonDAL();
            // if (e2.getSource() == cbbHTownDis.getSelectedItem()) {
            DistrictEntity District = (DistrictEntity) cbbHTownDis.getSelectedItem();
            System.out.println("ID of district: " + District.getDistricID().toString());
            HashSet<WardEntity> listWard = prsDal.getListWard(District.getDistricID());
            //
            removeE3();
            for (WardEntity ward : listWard) {
//                    if(cbbHTownWrd!=null & i ==0){
//                            cbbHTownWrd.removeAllItems();
//                            i=1;
//                        }
                cbbHTownWrd.addItem(ward);
            }
            // }
        }
    }

    public class E3 implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e3) {

            System.out.println("Clicking Ward");
            PersonDAL prsDal = new PersonDAL();
            // if (e3.getSource() == cbbHTownWrd.getSelectedItem()) {/
            WardEntity Ward = (WardEntity) cbbHTownWrd.getSelectedItem();
            System.out.println("Id of Ward: " + Ward.getWardID().toString());
            //JOptionPane.showMessageDialog(null,Ward.getWardID());
            HashSet<PopulationGroupEntity> listGroup = prsDal.getListGroup(Ward.getWardID());
            removeE4();
            for (PopulationGroupEntity group : listGroup) {
                cbbHTownGrp.addItem(group);
            }
            //  }
        }
    }

    public class E4 implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Click Group");
            PopulationGroupEntity group = (PopulationGroupEntity) cbbHTownGrp.getSelectedItem();
            System.out.println("ID group se duoc luu vao csdl....hehehe:  " + group.getPgroupID().toString());
            groupHTown = group.getPgroupID().toString();
        }
    }

    public class FilterProvinceRes implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e1) {
            System.out.println("Clicking Province District");
            PersonDAL prsDal = new PersonDAL();
//                if (cbbHTownDis.getSelectedIndex() == 0) {
//                    cbbHTownDis.removeAllItems();
//                    cbbHTownDis.addItem("--Select District--");
            ProvinceEntity Province = (ProvinceEntity) cbbResidencePrv.getSelectedItem();
            System.out.println("ID of province: " + Province.getProvinceID().toString());
            HashSet<DistrictEntity> listDistrict = prsDal.getListDistrict(Province.getProvinceID());
            int i = removeE6();
            if (i == 1) {
                for (DistrictEntity district : listDistrict) {
                    cbbResidenceDis.addItem(district);
                }
            }

        }
    }

    public class E6 implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Clicking District Residence");
            PersonDAL prsDal = new PersonDAL();
            DistrictEntity District = (DistrictEntity) cbbResidenceDis.getSelectedItem();
            System.out.println("ID of district: " + District.getDistricID().toString());
            HashSet<WardEntity> listWard = prsDal.getListWard(District.getDistricID());
            removeE7();
            for (WardEntity ward : listWard) {
                cbbResidenceWrd.addItem(ward);
            }
        }
    }

    public class E7 implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Clicking Ward Residence");
            PersonDAL prsDal = new PersonDAL();
            WardEntity Ward = (WardEntity) cbbResidenceWrd.getSelectedItem();
            System.out.println("Id of Ward: " + Ward.getWardID());
            HashSet<PopulationGroupEntity> listGroup = prsDal.getListGroup(Ward.getWardID());
            removeE8();
            for (PopulationGroupEntity group : listGroup) {
                cbbResidenceGrp.addItem(group);
            }
        }
    }

    public class E8 implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Click Group Residence");
            PopulationGroupEntity group = (PopulationGroupEntity) cbbResidenceGrp.getSelectedItem();
            System.out.println("ID group of Residence se duoc luu vao csdl....hehehe:  " + group.getPgroupID());
            groupRes = group.getPgroupID().toString();
        }
    }

    public void save() {
        int NUM_ARRAY = 10;
        System.out.println("click save");
        BufferedImage[] imagesArr = new BufferedImage[NUM_ARRAY];
        if (iconTempArr.size() == 10) {
            ProcessFile proFile = new ProcessFile();
            //IconList[] iconArr = lstTrainFace.getCellRenderer();

            for (int i = 0; i < NUM_ARRAY; i++) {
                IconList icon = iconTempArr.get(i);
                imagesArr[i] = icon.getImage();
            }
            //change to gray image
            ProcessImage proImage = new ProcessImage();
            //create folder tmp
            proFile.createFolder("../CIS_SProjectR2/data/tmp/");
            for (int i = 0; i < NUM_ARRAY; i++) {
                IplImage cvImage = new IplImage();
                cvImage = IplImage.createFrom(imagesArr[i]);
                cvImage = proImage.setGray(cvImage);
                cvSaveImage("../CIS_SProjectR2/data/tmp/" + (i + 1) + ".pgm", cvImage);
            }
            //for(int i = 0; i <)
            //proFile.createDatFile(txtID.getText());
            proFile.deleteFolder("../CIS_SProjectR2/data/tmp/");

            //proFile.saveBuffImageToDAT(imagesArr, txtID.getText(),"../CIS_SProjectR2/data/facedat/");
            System.out.println("Save array of images to dat successfully");
        }
        //do on db2
        DateFormat formatter;
        formatter = new SimpleDateFormat("yyyy-mm-dd");
        Calendar currentDate = Calendar.getInstance();
        PersonEntity prsEnt = new PersonEntity();
        PersonDAL prsDal = new PersonDAL();
//        //prsEnt.setPid(txfIdNumber.getText());auto
        prsEnt.setIdentity_number(txfIdNumber.getText());
        prsEnt.setFullname(txfFname.getText());
        try {
            prsEnt.setDob(formatter.parse(txfDOB.getText().toString()));
//            JOptionPane.showMessageDialog(this, txfDOB.getText().toString());
        } catch (ParseException ex) {
            Logger.getLogger(PFaceDetection.class.getName()).log(Level.SEVERE, null, ex);
        }
        prsEnt.setHometown(groupHTown);
        JOptionPane.showMessageDialog(this, groupRes);
        prsEnt.setPermanent_residence(groupRes);
        prsEnt.setEthnic(txfEthnic.getText());
        prsEnt.setReligion(txfRel.getText());
        prsEnt.setCharacteristic(txaChar.getText());
        prsEnt.setSaveImg(tempPath);
        prsDal.insertnewPerson(prsEnt);
    }
    private void lblClickToLoadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblClickToLoadMouseClicked
        // TODO add your handling code here:
        loadImageToLabelEvent();
    }//GEN-LAST:event_lblClickToLoadMouseClicked
    public void setNull() {
        txfDOB.setText("");
        txfEthnic.setText("");
        txfFname.setText("");
        txfIdNumber.setText("");
        txfRel.setText("");
        txaChar.setText("");
        lblLoadImg.setIcon(null);
    }

    public boolean checkInput() {
        // boolean result = false;
        if (txfIdNumber.getText().equals("")) {
            lblNote.setText("Please input indentity number");
            return false;
        } else if (txfFname.getText().equals("")) {
            lblNote.setText("Please input full namer");
            return false;
        } else if (txfDOB.getText().equals("")) {
            lblNote.setText("Please input birthday");
            return false;
        } else if (txfEthnic.getText().equals("")) {
            lblNote.setText("Please input Ethnic");
            return false;

        } else if (txfRel.getText().equals("")) {
            lblNote.setText("Please input religious");
            return false;
        } else if (txaChar.getText().equals("")) {
            lblNote.setText("Please input characteristic");
            return false;
        } else if (lblLoadImg.getIcon() == null) {
            lblNote.setText("Please choose a image");
            return false;
        } else if (!checkCombo()) {
            lblNote.setText("Please input hometown and residence");
            return false;
        } else if (iconTempArr.size() != 10) {
            lblNote.setText("Please input 10 face training data");
            return false;
        } else {
            return true;
        }
        // return result;
    }

    public boolean checkCombo() {
        boolean okHomeTown = true;
        boolean okResidence = true;
        //check combo HomeTown
        System.out.println("selected index of combo is: " + cbbHTownDis.getSelectedIndex());
        if (cbbHTownDis.getSelectedIndex() <= 0
                || cbbHTownGrp.getSelectedIndex() <= 0
                || cbbHTownPrv.getSelectedIndex() <= 0
                || cbbHTownWrd.getSelectedIndex() <= 0) {
            okHomeTown = false;
        }
        //check combo Residence
        if (cbbResidenceDis.getSelectedIndex() <= 0
                || cbbResidenceGrp.getSelectedIndex() <= 0
                || cbbResidencePrv.getSelectedIndex() <= 0
                || cbbResidenceWrd.getSelectedIndex() <= 0) {
            okResidence = false;
        }
        boolean result = okHomeTown && okResidence;
        System.out.println(result);
        return result;
    }
    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        // TODO add your handling code here:
        if (checkInput()) {
            save();
            lblNote.setText("");
        } else {
//            JOptionPane.showConfirmDialog(
//                    this, "Please check input", "Warning", JOptionPane.CLOSED_OPTION);
        }
    }//GEN-LAST:event_btnSaveActionPerformed

    public void filterFace(String name) {
        iconTempArr.clear();//empty icon
        indexArr.clear();//empty index

        // System.out.println("You chose me" + cmbTrainFace.getSelectedItem());
        //String currentNameSelect = (String) cmbTrainFace.getSelectedItem();
        for (int i = 0; i < iconTrainArr.size(); i++) {
            IconList icon = iconTrainArr.get(i);
            //all file
            if (name.equalsIgnoreCase("All image")) {
                iconTempArr.add(icon);
                indexArr.add(i);
            } else if (icon.getName().equalsIgnoreCase(name)) {
                iconTempArr.add(icon);
                indexArr.add(i);
            }
        }
        //set list cell render
        lstTrainFace = new JList(iconTempArr.toArray());
        VerticalIconRender render = new VerticalIconRender();
        lstTrainFace.setCellRenderer(render);
        scrollTrainFace.setViewportView(lstTrainFace);
        lstTrainFace.addMouseListener(new ListTrainngListener());
        //repaint list
        lstTrainFace.revalidate();
        lstTrainFace.repaint();
    }
    private void cmbTrainFaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTrainFaceActionPerformed
        // TODO add your handling code here:
        System.out.println("You chose me" + cmbTrainFace.getSelectedItem());
        String currentNameSelect = (String) cmbTrainFace.getSelectedItem();
        if (currentNameSelect != null) {
            filterFace(currentNameSelect);
          
        }
    }//GEN-LAST:event_cmbTrainFaceActionPerformed

    //add listening for list training face
    class ListTrainngListener extends MouseAdapter {

        JPopupMenu rightMenu = new JPopupMenu("Right menu");

        public ListTrainngListener() {

            /*
             * delete this face menu
             */
            JMenuItem deleteFace = new JMenuItem("Delete this face");
            //addMenu.setIcon(getIconResize("../CIS_SProjectR2/src/icon/Delete_16x16.png"));
            deleteFace.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    int index = lstTrainFace.getSelectedIndex();
                    if (index >= 0) {
                        //get name before delete
                        IconList tmpIcon = (IconList) lstTrainFace.getSelectedValue();
                        String nameIcon = tmpIcon.getName();
                        iconTempArr.remove(index);
                        iconTrainArr.remove(indexArr.get(index).intValue());
                        String currentNameSelect = (String) cmbTrainFace.getSelectedItem();

                        int pos = cmbTrainFace.getSelectedIndex();
                        filterFace(currentNameSelect);

                        //delete text in combo box if it no image
                        int check = 0;

                        for (int i = 0; i < iconTrainArr.size(); i++) {
                            IconList icon = iconTrainArr.get(i);
                            //all file
                            if (icon.getName().equalsIgnoreCase(currentNameSelect)) {
                                check++;
                            }
                        }

                        if (check == 0) {
                            for (int i = 0; i < cmbTrainFace.getItemCount(); i++) {
                                if (cmbTrainFace.getItemAt(i).equals(nameIcon)) {
                                    cmbTrainFace.removeItemAt(i);
                                }
                            }
                        }
                    }
                }
            });


            rightMenu.add(deleteFace);
            /*
             * delete all of face
             */
            JMenuItem deleteAllFace = new JMenuItem("Delete all face");
            //disableRegion.setIcon(getIconResize("../CIS_SProjectR2/src/icon/Delete_16x16.png"));
            deleteAllFace.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    //remove all item of combo
                    cmbTrainFace.removeAllItems();
                    cmbTrainFace.addItem("All image");
                    iconTrainArr = new ArrayList<IconList>();
                    iconTempArr = new ArrayList<IconList>();
                    filterFace("All image");
                }
            });
            rightMenu.add(deleteAllFace);

        }
        /*
         * set icon for right click menu
         */

        public ImageIcon getIcon(String path) {
            ImageIcon icon = new ImageIcon(path);
            return icon;
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            switch (e.getModifiers()) {
                case InputEvent.BUTTON1_MASK: {
                    if (e.getClickCount() == 2) {
                        /*
                         * double click
                         */
                    }

                    break;
                }
                case InputEvent.BUTTON2_MASK: {

                    System.out.println("That's the MIDDLE button");

                    break;
                }
                case InputEvent.BUTTON3_MASK: {
                    System.out.println("That's the RIGHT button");
                    //rightMenu.pack();
                    int index = lstTrainFace.getSelectedIndex();
                    if (index >= 0) {
                        rightMenu.show(e.getComponent(), e.getX(), e.getY());
                    }
                    break;
                }
            }
        }
    }

    private void jTabbedPane3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane3MouseClicked
        // TODO add your handling code here:
        //btnOpenFolder.setEnabled(false);
        if (jTabbedPane3.getSelectedIndex() == 1){
            btnOpenFolder.setEnabled(false);
        }else{
            btnOpenFolder.setEnabled(true);
        }
        
    }//GEN-LAST:event_jTabbedPane3MouseClicked

    private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetActionPerformed
        // TODO add your handling code here:
        setNull();
    }//GEN-LAST:event_btnResetActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnOpenFolder;
    private javax.swing.JButton btnReset;
    private javax.swing.JButton btnSave;
    private javax.swing.JComboBox cbbHTownDis;
    private javax.swing.JComboBox cbbHTownGrp;
    private javax.swing.JComboBox cbbHTownPrv;
    private javax.swing.JComboBox cbbHTownWrd;
    private javax.swing.JComboBox cbbResidenceDis;
    private javax.swing.JComboBox cbbResidenceGrp;
    private javax.swing.JComboBox cbbResidencePrv;
    private javax.swing.JComboBox cbbResidenceWrd;
    public javax.swing.JComboBox cmbTrainFace;
    private javax.swing.JFileChooser fileChooseFolder;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel20;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JPanel jPanel23;
    private javax.swing.JPanel jPanel25;
    private javax.swing.JPanel jPanel26;
    private javax.swing.JPanel jPanel30;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel46;
    private javax.swing.JPanel jPanel47;
    private javax.swing.JPanel jPanel48;
    private javax.swing.JPanel jPanel49;
    private javax.swing.JPanel jPanel50;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane3;
    private javax.swing.JSplitPane jSplitPane4;
    private javax.swing.JSplitPane jSplitPane5;
    private javax.swing.JTabbedPane jTabbedPane3;
    private javax.swing.JLabel lblClickToLoad;
    private javax.swing.JLabel lblLoadImg;
    private javax.swing.JLabel lblNote;
    public javax.swing.JList lstFaceImages;
    public javax.swing.JList lstThumbnails;
    public javax.swing.JList lstTrainFace;
    private javax.swing.JPanel pnlFaceAnotations1;
    private javax.swing.JPanel pnlShowAdd;
    public javax.swing.JPanel pnlShowImage;
    public javax.swing.JScrollPane scrollFaceImages;
    private javax.swing.JScrollPane scrollPanelThumb;
    public javax.swing.JScrollPane scrollTrainFace;
    private javax.swing.JSplitPane splMain1;
    private javax.swing.JTextArea txaChar;
    private javax.swing.JTextField txfDOB;
    private javax.swing.JTextField txfEthnic;
    private javax.swing.JTextField txfFname;
    private javax.swing.JTextField txfIdNumber;
    private javax.swing.JTextField txfRel;
    // End of variables declaration//GEN-END:variables
}

class ListImageListener extends MouseAdapter {

    JPopupMenu rightMenu = new JPopupMenu("Right menu");

    public ListImageListener() {

        /*
         * Enable Region menu
         */
        JMenuItem enableRegion = new JMenuItem("Enable Region");
        //addMenu.setIcon(getIconResize("../CIS_SProjectR2/src/icon/Delete_16x16.png"));
        enableRegion.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int index = GLPDetect.lstThumbnails.getSelectedIndex();
                if (index >= 0) {
                    System.out.println("Enable Region");

                    GLPDetect.toggleRegion = true;
                    GLPDetect.pnlShowImage.revalidate();
                    GLPDetect.pnlShowImage.repaint();
                }
            }
        });


        rightMenu.add(enableRegion);
        /*
         * Disable Region menu
         */
        JMenuItem disableRegion = new JMenuItem("Disable Region");
        //disableRegion.setIcon(getIconResize("../CIS_SProjectR2/src/icon/Delete_16x16.png"));
        disableRegion.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int index = GLPDetect.lstThumbnails.getSelectedIndex();
                if (index >= 0) {
                    GLPDetect.toggleRegion = false;
                    GLPDetect.pnlShowImage.revalidate();
                    GLPDetect.pnlShowImage.repaint();
                    System.out.println("Disable Region");
                }

            }
        });
        rightMenu.add(disableRegion);

        /*
         * Detect This Face menu
         */
        JMenuItem detectFace = new JMenuItem("Detect This Image");
        //disableRegion.setIcon(getIconResize("../CIS_SProjectR2/src/icon/Delete_16x16.png"));
        detectFace.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                final int index = GLPDetect.lstThumbnails.getSelectedIndex();
                if (index >= 0) {
                    new Thread() {

                        @Override
                        public void run() {
                            FaceDetection objDetect = new FaceDetection();
                            GLImageList.load(index);
                            IplImage image = GLImageList.getCVImage();
                            objDetect.detectFace(image, index);
                            System.out.println("Detect This Face");
                            GLPCustom.updateListFace();
                            interrupt();
                        }
                    }.start();

                }
            }
        });
        rightMenu.add(detectFace);

        /*
         * Detect All Faces menu
         */
        JMenuItem detectAllFaces = new JMenuItem("Detect All of Images");
        //disableRegion.setIcon(getIconResize("../CIS_SProjectR2/src/icon/Delete_16x16.png"));
        detectAllFaces.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                final int index = GLPDetect.lstThumbnails.getSelectedIndex();
                if (index >= 0) {
                    new Thread() {

                        @Override
                        public void run() {

                            System.out.println("Detect All Face Start");
                            FaceDetection objDetect = new FaceDetection();
                            for (int i = 0; i < GLImageList.getLength(); i++) {
                                GLImageList.load(index);
                                IplImage image = GLImageList.getCVImage();
                                objDetect.detectFace(image, i);
                            }

                            GLPCustom.updateListFace();
                            System.out.println("Detect All Face Finished");
                            interrupt();
                        }
                    }.start();

                }

            }
        });
        rightMenu.add(detectAllFaces);


    }
    /*
     * set icon for right click menu
     */

    public ImageIcon getIcon(String path) {
        ImageIcon icon = new ImageIcon(path);
        return icon;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        switch (e.getModifiers()) {
            case InputEvent.BUTTON1_MASK: {
                if (e.getClickCount() == 2) {
                    /*
                     * double click
                     */
                    if (GLImageList.getLength() > 0) {
                        int index = 0;

                        ProcessImage objImg = new ProcessImage();
                        index = GLPDetect.lstThumbnails.getSelectedIndex();
                        GLImageList.load(index);
                        BufferedImage image = objImg.resize(
                                GLImageList.getImage(),
                                GLPDetect.pnlShowImage.getWidth(),
                                GLPDetect.pnlShowImage.getHeight());


                        /*
                         * check region on a image
                         */
                        if (GLPCustom.positionArr[index] == null) {
                            /*
                             * if not exist
                             */
                            GLPCustom.positionArr[index] = new FaceRegion();
                        }
                        /*
                         * if exist
                         */
                        GLPCustom.index = index;
                        GLPCustom.image = image;
                        GLPCustom.fileName = GLImageList.getFileNames(index);


                        GLPDetect.pnlShowImage.setLayout(new BoxLayout(GLPDetect.pnlShowImage, BoxLayout.PAGE_AXIS));

                        GLPDetect.pnlShowImage.repaint(); //repaint a image
                        GLPDetect.pnlShowImage.revalidate(); //clear
                        GLPDetect.pnlShowImage.add(GLPCustom);
                    }
                }
                break;
            }
            case InputEvent.BUTTON2_MASK: {

                System.out.println("That's the MIDDLE button");

                break;
            }
            case InputEvent.BUTTON3_MASK: {
                System.out.println("That's the RIGHT button");
                //rightMenu.pack();
                int index = GLPDetect.lstThumbnails.getSelectedIndex();
                if (index >= 0) {
                    rightMenu.show(e.getComponent(), e.getX(), e.getY());
                }
                break;
            }
        }
    }
}
